home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9343 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.PBI.net!usenet
  2. From: mich@pbinet.com
  3. Newsgroups: comp.lang.c
  4. Subject: Re: free() wont free
  5. Date: 9 Mar 1996 16:49:42 GMT
  6. Organization: Pacific Bell Internet Services
  7. Message-ID: <4hscr6$efq@SNFC21_SRVR_WWW.PBI.net>
  8. References: <31398D95.5701DCB4@halo.tau.ac.il> <4hn41e$2dh@druid.borland.com>
  9. Reply-To: mich@pbinet.com
  10. NNTP-Posting-Host: ppp-5-36.rdcy01.pbinet.com
  11. X-Newsreader: IBM NewsReader/2 v1.03
  12.  
  13. In <4hn41e$2dh@druid.borland.com>, pete@borland.com (Pete Becker) writes:
  14. >    Second, assume that free() does its job. The problem is not that 
  15. >free() doesn't work, but that your program allocates memory that it never 
  16. >frees. Track through all of the memory allocations that it does, find out 
  17. >where the leaks are, and fix them. If you can't find the leaks you aren't 
  18. >looking hard enough.
  19.  
  20. Yes, assuming free has infact freed memory blocks is about all you can do.
  21. For allocation problems, look for freeing the same pointer more than once. This
  22. is a common mistake. Consider;
  23.  
  24. myfunc()
  25. {
  26.     void *pMem = malloc(100);
  27.     free(pMem);
  28.     free(pMem);
  29. }
  30.  
  31. At best the results of this will be unpredictable. Look for attempts to free invalid
  32. pointers, or requests to allocate already allocated ones. And always check the
  33. pointer after allocating, it can save you hours of debugging. malloc is really a
  34. request, not a command. For whatever reason the system my not be able to
  35. allocate your request everytime. malloc returns a null pointer in these cases.
  36.  
  37.